<template>
  <div class="Tree">
    <div
      v-for="(item,index) in folder"
      :key="index"
      @mouseover="selected=item.name"
      @mouseleave="selected=''"
      @click.stop="select(item)"
    >
      <span>{{ item.name }}</span>
      <el-collapse-transition>
        <tree
          v-show="selected==item.name"
          @mouseover="selected=item.name"
          @mouseleave="selected=''"
          class="Treechild"
          v-if="item.children"
          :folder="item.children"
        ></tree>
      </el-collapse-transition>
    </div>
    <iframe
      class="iframe"
      :style="{width:'1.38rem',height:(folder.length*0.54)+'rem'}"
      frameborder="0"
    ></iframe>
  </div>
</template>

<script lang="ts">
import { Component, Vue, Prop, Watch } from "vue-property-decorator";
import { publicAPIModule } from "@/store/modules/public";
import { AuxiliaryMonitorModule } from "@/store/modules/AuxiliaryMonitor";
import { JointInspectionModule } from "@/store/modules/JointInspection";
@Component
export default class tree extends Vue {
  @Prop() folder!: [];
  // 当前地市信息
  @Prop({ default: () => [] })
  CurrentOrg;
  // 地市名
  @Prop({ default: () => [] })
  dzLoginName;
  public selected: string = "";
  //点击的路由
  routers: any = {};
  select(item) {
    // console.log("item", itempath);

    // 判断是否进入辅控、在线监测、锁具管理路由--start
    let id = item.id;
    let parentId: any = id.split("-")[0];
    // console.log(parentId);
    this.$emit("Acitve", parentId);
    if (["1", "2", "3"].indexOf(parentId) >= 0) {
      this.setbdzCode(item.path);
      return false;
    }
    // 判断是否进入辅控、在线监测、锁具管理路由--end
    // this.selected = "";
    // console.log("itemchild", item);
    this.routers = item;

    // console.log("消防系统item:", item);
    if (item.name === "在线监测") {
      // window.open(
      //   "http://10.193.23.21:28883/epribigdata/jsp/index.html?ssdsid=" +
      //     this.newCurrentOrg.SSDSBM +
      //     "&&loginname=" +
      //     this.newDzLoginName +
      //     "A&bq=zxjc"
      // );
      // iframe嵌套 装置总数跳转页面
      let list = "";
      if (this.newCurrentOrg.SSDSBM == "8a1ea5c64bdebad1014bdebc4cbf0001") {
        //省公司
        list = "ssds=" + null + "&zzzt=null&yxzt=1";
      } else {
        //地市公司
        list = "ssds=" + this.newCurrentOrg.SSDSMC + "&zzzt=null&yxzt=1";
      }
      let url =
        "http://10.193.23.21:28883/epribigdata/jsp/tg_zt/xinyi_zxjc/yczz.jsp?" +
        list;
      window.open(url, "_blank");

      // this.$router.push({
      //   path: "/warningtosolve/xyddjc",
      //   query: {
      //     list: list,
      //     urlType: "yczz",
      //   },
      // });
    } else if (item.name === "带电检测") {
      // window.open(
      //   "http://10.193.23.21:28883/epribigdata/jsp/index.html?ssdsid=" +
      //     this.newCurrentOrg.SSDSBM +
      //     "&&loginname=" +
      //     this.newDzLoginName +
      //     "A&bq=ddjc"
      // );
      // iframe嵌套 已测设备链接跳转页面
      let list = "";
      if (this.newCurrentOrg.SSDSBM == "8a1ea5c64bdebad1014bdebc4cbf0001") {
        //省公司
        list = "jczt=0&ssds=";
      } else {
        //地市公司
        list = "jczt=0&ssds=" + this.newCurrentOrg.SSDSBM;
      }
      let url =
        "http://10.193.23.21:28883/epribigdata/jsp/tg_zt/xyddjc/ycsb.jsp?" +
        list;
      window.open(url, "_blank");
      // this.$router.push({
      //   path: "/warningtosolve/xyddjc",
      //   query: {
      //     list: list,
      //     urlType: "ddjc",
      //   },
      // });

      // } else if(item.id==='1-1' || item.id==='1-2' || item.id==='1-3' || item.id==='1-4' || item.id==='1-5') {
      //   this.$router.push({ path: item.path, query:this.SubstationList });
      // } else if(item.id==='2-1' || item.id==='2-2' || item.id==='2-3' || item.id==='2-4' || item.id==='2-5'|| item.id==='2-6'|| item.id==='2-7'|| item.id==='2-8'|| item.id==='2-9'|| item.id==='2-10') {
      //   this.$router.push({ path: item.path, query:this.SubstationList });
    } else if (item.name === "可视化编辑器") {
      (this as any).$services
        .getEditor({ method: "get" })
        .then((result: any) => {
          // console.log("result:", result);
          // console.log("55555555555555555555555555555555555555:", (window as any).VUE_APP_EDITORURL);
          let data = result.data;

          window.open(data);
        })
        .catch((err: object) => {
          console.log(err);
        });
    } else if (item.name === "设备全景") {
      const routeOne: any = this.$router.resolve({
        name: "EquipmentPanoramic",
        query: {},
      });
      // console.log("routeOne.href:", routeOne.href);
      window.open(routeOne.href);
    } else {
      // console.log( publicAPIModule.queryHasDataStationsList[0] );
      // if (
      //   publicAPIModule.queryHasDataStationsList &&
      //   publicAPIModule.queryHasDataStationsList[0]
      // ) {
      //   this.$router.push({ path: item.path, query: this.SubstationList });
      // } else {
      //   this.$router.push({ path: item.path });
      // }
      // if (this.bdzCode && this.bdzCode[0]) {
      //   this.$router.push({ path: item.path, query: this.bdzCode[0] });
      // } else {
      this.$router.push({ path: item.path });
      // }
    }
  }

  get SubstationList() {
    return publicAPIModule.queryHasDataStationsList[0];
  }
  get SubstationList2() {
    return publicAPIModule.queryHasDataStationsList;
  }
  get newCurrentOrg() {
    let CurrentOrg = this.CurrentOrg;
    return CurrentOrg;
  }

  get newDzLoginName() {
    let dzLoginName = this.dzLoginName;
    return dzLoginName;
  }
  // 监听变电站code
  // bdzCode = [];
  // 各地市默认的变电站
  public cityBdz = {
    // 泰安默认变电站
    "8a1ea5c64bdebad1014bdebc5c21078c": {
      stationName: "220kV天平变电站",
      stationId: "1500000001",
    },
    // 如果没有默认站
    default: {
      stationName: "",
      stationId: "",
    },
  };
  // is = 0;
  setbdzCode(path) {
    // 获取当前用户信息
    let CompanyList = JointInspectionModule.CompanyList || [];
    let CurrentOrg = CompanyList[0] || {};
    // 根据用户信息所属地市，获得默认变电站
    let cityBdz = this.cityBdz[CurrentOrg.code] || this.cityBdz["default"];
    let query = {
      code: cityBdz.stationId || "",
      name: cityBdz.stationName || "",
    };
    AuxiliaryMonitorModule.setStationName(query);
    this.$router.push({ path: path, query });
  }
}
</script>
<style lang="scss" scoped>
.Tree {
  position: relative;
  overflow: hidden;
  > div {
    position: relative;
    cursor: pointer;
    width: 1.38rem;
    height: 0.54rem;
    display: flex;
    align-items: center;
    background-size: 100% 100%;
    background-position: center;
    justify-content: center;
    background-image: url("../../assets/img/HomePage/nor_cd.png");
    font-size: 0.18rem;
    &:hover {
      background-image: url("../../assets/img/HomePage/cli_cd.png");
    }
    > span {
      color: #fff;
    }
    position: relative;
  }
  .Treechild {
    position: absolute;
    top: 0rem;
    left: 1.38rem;
  }
  .iframe {
    width: 100px;
    height: 500px;
    position: absolute;
    top: 0px;
    left: 0px;
    z-index: 1;
    opacity: 0.1;
    background: none;
    pointer-events: none;
  }
}
</style>